window.onload=function (){
    showLoginInfo();
    showProduct(1);
}


/**
 * 显示登录信息
 */
function  showLoginInfo(){
    axios.get("user/getLoginUser",null).then(e =>{
        var info=e.data
        if (e.data !=null && e.data !=''){
            $("infoDiv").innerHTML="欢迎光临"+"  "+info.name;

        }
        else {
            $("infoDiv").innerHTML="你好,请先 <a href='login.html'>登录</a>"
        }
    })

}

function  showProduct(pageNO){
    axios.get("/product/findByItem",{
        params:{
            pageNO,
            name:$("name").value,
            startDate:$("startDate").value,
            endDate:$("endDate").value
        }
    }).then( e=>{
        var info =e.data;
        //显示商品数据  records
        var str ="";
        for (i=0;i<info.records.length;i++){
            var obj =info.records[i];
            str +=`<div>
            <img src="/productImg/${obj.img}" width="200px" height="200px"><br>
                    ${obj.name}<br>单价:${obj.price}<br>已售完:${obj.sum}件<br>
                    <a href="/custom/shop.html?productId=${obj.id}">购买</a><a href="/custom/shopm.html?productId=${obj.id}">查看</a></div>`

        }
        $("productDiv").innerHTML=str;

        var cutStr="";
        for (var i=1;i<=info.pages;i++){
            cutStr +=`<a href="javascript:showProduct(${i})">${i}</a>`
        }
        $("cutPageDiv").innerHTML=cutStr

    });

}